package com.pk.platform.business.privilege.service.impl;

import java.util.List;
import java.util.Set;

import com.pk.platform.business.privilege.dao.IDeptDao;
import com.pk.platform.business.privilege.service.IDeptService;
import com.pk.platform.business.privilege.vo.DeptVO;
import com.pk.platform.domain.privilege.Department;
import com.pk.platform.domain.privilege.User;
import com.pk.platform.util.page.ListPage;
import com.pk.platform.util.page.Pager;

public class DeptServiceImpl implements IDeptService {

	private IDeptDao deptDao;
	
	public Department queryDeptById(Long id)
	{
		return deptDao.get(Department.class, id);
	}
	
	public void addDept(Department dept) {
		deptDao.add(dept);
	}
	
	public void updateDept(Department dept)
	{
		Department d = deptDao.get(Department.class, dept.getId());
		d.setDeptName(dept.getDeptName());
	}

	public void delDepts(String[] deptIds) {
		for(String id : deptIds)
		{
			Long deptId = Long.parseLong(id);
			Department dept = deptDao.get(Department.class, deptId);
			Set<User> userSet = dept.getUserSet();
			for(User user : userSet)
			{
				user.setDept(null);
			}
			deptDao.delete(Department.class, deptId);
		}
	}
	
	public List<Department> queryDeptList()
	{
		return deptDao.queryDeptList();
	}

	public ListPage queryDept(DeptVO dvo, Pager pager) {
		return deptDao.queryDept(dvo, pager);
	}

	public IDeptDao getDeptDao() {
		return deptDao;
	}

	public void setDeptDao(IDeptDao deptDao) {
		this.deptDao = deptDao;
	}

}
